
class MyApp extends BaseClass {
    private _net: NetWork = new NetWork()
    private _loginRequest: msg.MSG_LoginRequest = null

    constructor() {
        super()
        console.log("MyApp 构造")
        App.ResourceUtils.loadGroup("game_preload", this.onResourceLoadComplete, this.onResourceLoadProgress, this)
        this._net.MsgHandleMgr = new MainMessageHandleMgr()
        this._net.MsgHandleMgr.InitAll()
        this._net.OnConnect = function (net: NetWork) {
            net.Send(Protocol.MSG_LoginRequest, MyApp.getInstance()._loginRequest)
        }
        this._net.OnClose = function (net: NetWork) {
            console.log("SocketClose")
        }
        this._net.OnReceive = function (net: NetWork, buf: egret.ByteArray) {
            let mt = Protocol.All[MakeCmdIndex(buf)]
            if (mt) {
                console.log("收到消息: " + mt.Name)
            } else {
                console.log("未知消息: ", MakeCmdIndex(buf))
            }
        }
    }

    private onResourceLoadComplete(param1: any, param2: any): void {
        App.SceneManager.runScene(SceneConsts.LODDY);
        this.loginServer()
        //App.SceneManager.runScene(SceneConsts.TEST)
    }
    private onResourceLoadProgress(itemsLoaded: number, itemsTotal: number): void {
        //App.ControllerManager.applyFunc(ControllerConsts.Loading, LoadingConst.SetProgress, itemsLoaded, itemsTotal);
    }


    private loginServer() {
        this._loginRequest = Protocol.MSG_LoginRequest.New()
        this._loginRequest.account = "AAAAA"
        this._loginRequest.version = 1
        this._loginRequest.gasdk_string = "{}"
        this._loginRequest.platform = "win"
        this._loginRequest.check_version = "2222"
        this._net.Connect("192.168.174.146", 9999);
    }
}